package com.label.Utils;

import com.label.Model.Do.ViewData;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;

public class WordUploadUtil {

    public static void down(File file) throws IOException {
        ViewData viewData=new ViewData();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        //读取word文档
        String value = "";
        String filePath = file.getPath();
        try{
            FileInputStream in = new FileInputStream(filePath);
            // 处理docx格式 doc 与docx格式共用
            XWPFDocument document = new XWPFDocument(in);
            List<XWPFTable> tables = document.getTables();

            // 迭代文档中的表格
            for (XWPFTable table:tables) {

                //迭代行，默认从0开始,可以依据需要设置i的值,改变起始行数，也可设置读取到那行，只需修改循环的判断条件即可
                for (int i = 0; i < table.getRows().size(); i++) {
                    XWPFTableRow tr = table.getRow(i);

                    //迭代列，默认从0开始
                    for (int j = 0; j < tr.getTableCells().size(); j++) {
                        XWPFTableCell td = tr.getCell(j);
                        String s=td.getText();

                        if(i == 0 && j == 3){
                            System.out.println("单位职务"+s);
                        }
                        if (i == 1 && j== 1) {
                            System.out.println("谈话对象"+s);
                        }

                    }
                }
            }
        }catch(Exception e) {
            e.printStackTrace();
        }

    }


}
